<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<style>
    input.error{
        border:1px solid red;
    }
    span.error{
        padding-top:10px;
        color: #f00;
        font-size:12px;
    }
</style>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑新品发布</h5>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">发布标题:</label>
                            <div class="col-sm-6">
                                <input type="text" name="title" value="{$info.title}" class="form-control">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">发布内容:</label>
                            <div class="col-sm-6">
                                <textarea name="content" class="form-control">{$info.content}</textarea>
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">选择商品:</label>
                            <div class="col-sm-6">
                                <button type="button" class="btn btn-success" onclick="selectGoods();">选择商品信息</button>
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        
                        <div class="form-group goods-box">
                            <label class="col-sm-2 control-label">已选商品信息:</label>
                            <div class="col-sm-8">
                                <table class="table table-hover table-bordered">
                                    <thead class="biaoge">
                                        <tr>
                                            <th style="width:30%">商品名称</th>
                                            <th style="width:20%">缩略图</th>
                                            <th style="width:15%">所属分类</th>
                                            <th style="width:20%">金额</th>
                                            <th style="width:15%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="goods_list">
                                        {foreach name="goods_list" item="v"}
                                        <tr>
                                            <input type="hidden" class="text_id" name="goods_id[]" value="{$v.id}">
                                            <td>{$v.goods_name}</td>
                                            <td><img src="{$v.thumb_url}" width="100px" height="100px" onerror="this.src='__PUBLIC__/admin/img/nopic.jpg'"/></td>
                                            <td>{$v.cate_name}</td>
                                            <td>{$v.shop_price}</td>
                                            <td><button type="button" class="btn btn-danger btn-xs" onclick="$(this).parent().parent().remove();"><i class="fa fa-close"></i>&nbsp;移除</button></td>
                                        </tr>
                                        {/foreach}
                                    </tbody>	
                                </table>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">选择视频:</label>
                            <div class="col-sm-6">
                                <button type="button" class="btn btn-success" onclick="selectVideos();">选择视频信息</button>
                            </div>
                        </div>
                        
                        <div class="form-group video-box">
                            <label class="col-sm-2 control-label">已选视频信息:</label>
                            <div class="col-sm-8">
                                <table class="table table-hover table-bordered">
                                    <thead class="biaoge">
                                        <tr>
                                            <th style="width:10%">标题</th>
                                            <th style="width:20%">简介</th>
                                            <th style="width:15%">封面图</th>
                                            <th style="width:30%">视频url</th>
                                            <th style="width:15%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="video_list">
                                        {foreach name="video_list" item="v"}
                                            <tr>
                                                <input type="hidden" name="video_id[]" value="{$v.id}">
                                                <td>{$v.title}</td>
                                                <td>{$v.describe}</td>
                                                <td>
                                                    <img src="{$v.cover_img}" width="100px" height="100px" onerror="this.src='__PUBLIC__/admin/img/nopic.jpg'"/>
                                                </td>
                                                <td>
                                                    <a href="{$v.video_url}" target="_bank">...{$v.video_path}</a>
                                                </td>
                                                <td>
                                                    <button type="button" class="btn btn-danger btn-xs" onclick="$(this).parent().parent().remove();"><i class="fa fa-close"></i>&nbsp;移除</button>
                                                </td>
                                            </tr>
                                        {/foreach}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">点赞数量:</label>
                            <div class="col-sm-6">
                                <input type="text" name="praise_num" value="{$info.praise_num}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">阅读数量:</label>
                            <div class="col-sm-6">
                                <input type="text" name="read_num" value="{$info.read_num}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否显示:</label>
                            <div class="col-sm-6">
                                <label class="radio-inline"><input type="radio" name="status" {if condition='$info.status eq 1'}checked="checked"{/if} value="1">是</label>
                                <label class="radio-inline"><input type="radio" name="status" {if condition='$info.status eq 0'}checked="checked"{/if} value="0">否</label>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <input type="hidden" name="id" value="{$info.id}" />
                        
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit" id="doSubmit">保存内容</button>
                                <button class="btn btn-primary" type="button" onclick="goBackLst('/{$Request.module}/new_publish/lst');">返回</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="__PUBLIC__/admin/Huploadify/jquery.Huploadify.js"></script>
<script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
<script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>
<!-- iCheck -->
<script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
<script src="__PUBLIC__/admin/js/common/ajax.js"></script>
<script type="text/javascript">

    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });

    var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
    $('#form').validate({
        errorElement : 'span',
        debug: true,//只验证不提交表单
        //layer ajax提交表单
        submitHandler:function(){
            // 序列化 表单数据 后提交 ，太简洁了
            post("{:url('NewPublish/edit')}",'POST',$('#form').serialize(),1);
            return false;
        },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法

        rules:{
            shop_id:{required:true},
            goods_id:{required:true},
            title:{required:true},
            content:{required:true},
            praise_num:{number:true},
            read_num:{number:true}
        },

        messages:{
            shop_id:{required:icon+'必选'},
            goods_id:{required:icon+'必填'},
            title:{required:icon+'必填'},
            content:{required:icon+'必填'},
            praise_num:{number:icon+'请填写数字'},
            read_num:{number:icon+'请填写数字'}
        }
    });
    
    function selectGoods(){
        var goods_id = new Array();
        //过滤选择重复信息
        $('input[name*=goods_id]').each(function(i,o){
            goods_id.push($(o).val());
        });
        var params = '';
        if (goods_id.length) {
            params += '/goods_id/' + goods_id;
        }
        var goodsurl = "/{$Request.module}/getgoods/lst" + params;
        layer.open({
            type: 2,
            title: '选择商品信息',
            shadeClose: true,
            shade: 0.3,
            area: ['70%', '80%'],
            content: goodsurl
        });
    }

    function call_backgoods(table_html){
        layer.closeAll('iframe');
        $('#goods_list').append(table_html);
    }
    
    function selectVideos(){
        var video_id = new Array();
        //过滤选择重复信息
        $('input[name*=video_id]').each(function(i,o){
            video_id.push($(o).val());
        });
        var params = '';
        if (video_id.length) {
            params += '/video_id/' + video_id;
        }
        var video_url = "/{$Request.module}/Video/getVideoList"+params;
        layer.open({
            type: 2,
            title: '选择视频信息',
            shadeClose: true,
            shade: 0.3,
            area: ['70%', '80%'],
            content: video_url
        });
    }
    
    function call_backvideo(table_html) {
        layer.closeAll('iframe');
        $('#video_list').append(table_html);
    }
    
    function cl(){
        location.href = "{:url('NewPublish/lst')}";
    }
</script>

</body>
</html>
